<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php echo $this->template('header.phtml') ?>
<?php if ($this->get('writable_warning')) echo $this->template('writable.phtml');?>
<div class="bar-head">
    <h4>Updatespezifische Einstellung</h4>
</div>
<ul class="bare-list">
<li><input type="checkbox" id="maintenance" value="1" checked="checked" /> &nbsp;
<label for="maintenance">Während der Installation bzw. dem Upgrade Wartungsmodus für den Shop aktivieren? (Keine Bestellungen möglich)</label>
</li>
</ul>

<div class="bar-head">
    <h4>Neue Erweiterungen installieren</h4>
</div>
<script type="text/javascript">
<!--
 function connectPrepare(form) {
    new Ajax.Request(form.action, { 
      method:'post',
      parameters: {install_package_id: form.install_package_id.value},
      onCreate: function() {
          $('prepare_package_result').update(
                '<div class="loading-mask" id="loading_mask_loader">'+
                ' <p class="loader">'+
                ' <img src="<?php echo $this->baseUrl()?>/skin/images/ajax-loader-tr.gif" alt="Loading..."/><br/>Please wait...'+
                ' </p>'+
                '</div>'
          );
          $('loading_mask_loader').style.position = 'relative';
          $('loading_mask_loader').top = 0;
          $('prepare_package_result').show();
      },
      onSuccess: function(transport) {
          // @TODO: check transport.status to show errors
          $('prepare_package_result').update(transport.responseText);
          $('prepare_package_result').show();
      },
      onFailure: function() {
          $('prepare_package_result').update(
              '<div id="packages_failure">' +
              ' <ul class="msgs"> ' +
              '  <li>' +
              '   <ul class="error-msg">' +
              '     <li>Connection Error try again later.</li>' +
              '   </ul>' +
              '  </li>' +
              ' </ul>' +
              '</div> '
          );
      }
    });
    return(false);
 }
//-->
</script>
<form action="<?php echo $this->url('connectPreparePackagePost')?>" method="post" onsubmit="return connectPrepare(this)">
    <ul class="bare-list">
        <li>
            <span class="step-count">1</span> &nbsp; Nach Modulen suchen auf <a href="http://connect.magentocommerce.com/" target="Magento_Connect">Magento Connect</a>.
        </li>
        <li>
            <span class="step-count">2</span> &nbsp;
            <label for="install_package_id">Extension Key zur Installation einf&uuml;gen:</label> <input type="text" id="install_package_id" name="install_package_id" style="width:300px"/>
            <button type="submit">Installieren</button>
        </li>
    </ul>
</form>

<br/>

<div class="connect-packages" id="prepare_package_result" style="display:none;"></div>
<br/>

<div class="bar-head">
    <h4>Modul Paket hochladen (.tgz Archiv)</h4>
</div>
<form action="<?php echo $this->url('connectInstallPackageUpload')?>" method="post" target="connect_iframe" onsubmit="onSubmit(this)" enctype="multipart/form-data">
    <ul class="bare-list">
        <li><span class="step-count">1</span> &nbsp; Herunterladen oder Paket erstellen.</li>
        <li>
            <span class="step-count">2</span> &nbsp; Modul Paket hochladen:
            <label for="file"></label>
            <input type="file" id="file" name="file"/>
            <button type="submit">Hochladen &amp; Installieren</button>
        </li>
    </ul>
</form>

<br/><br/>
<div class="bar-head">
    <h4>Bestehende Erweiterungen verwalten</h4>
    <?php if (empty($_GET['updates'])): ?>
        <span class="bar-head-btn f-right"><button type="button" class="f-right" onclick="checkForUpdateClick()">Auf Upgrades &uuml;berpr&uuml;fen</button></span>
    <?php endif; ?>
</div>
<?php $packages = $this->get('connect')->getAllInstalledPackages(); $i = 0; $cnt = count($packages); ?>
<?php $channelConfig=$this->get('channel_config');?>
<script type="text/javascript">
    function formSubmit(id)
    {
        var formObj = $(id);
        if (onSubmit(formObj)) {
            formObj.submit();
        }
    }
</script>
<?php foreach ($packages as $channel=>$pkgs): ?>

<form id="connect_packages_<?php echo $i ?>" class="connect-packages" action="<?php echo $this->url('connectPackagesPost')?>" method="post" target="connect_iframe">
    <div class="no-display">
        <input type="hidden" id="ignore_local_modification" name="ignore_local_modification" value=""/>
        <input type="hidden" name="form_id" value="connect_packages_<?php echo $i ?>"/>
    </div>
    <p class="nm"><button type="button" onclick="formSubmit('connect_packages_<?php echo $i ?>')" class="f-right">&Auml;nderungen &uuml;bernehmen</button></p>
    <h2 class="page-head">Channel: <?php echo $channelConfig->getChannelLabel($channel); ?></h2>
    <p class="f-right"><label for="clean_sessions">Alle Sitzungen nach erfolgreicher Installation oder Upgrade leeren: <input type="checkbox" id="clean_sessions"/></label></p>
    <div class="clear"></div>

    <table cellspacing="0" cellpadding="0" width="100%">
        <?php if (!empty($_GET['updates'])): ?>
            <col width="190" />
            <col width="60" />
            <col width="60" />
            <col width="160"  />
            <col width="170" />
        <?php else: ?>
            <col width="200" />
            <col width="100" />
            <col width="70"  />
            <col width="180" />
        <?php endif; ?>
        <thead>
            <tr>
                <th class="first">Paket Name</th>
                <th class="a-center">Installiert</th>
                <?php if (!empty($_GET['updates'])): ?><th class="a-center">Verf&uuml;gbar</th><?php endif; ?>
                <th>Aktionen</th>
                <th class="last">Beschreibung</th>
            </tr>
        </thead>
        <tbody>
        <?php foreach ($pkgs as $pkgName=>$pkg): ?>
            <tr class="<?php echo $pkg['status']?>">
                <td class="first"><?php echo $pkgName?></td>
                <td class="a-center"><?php echo $pkg['version'].' ('.$pkg['stability'].')'?>&nbsp;</td>
                <?php if (!empty($_GET['updates'])): ?><td class="a-center"><?php echo $pkg['upgrade_latest']?>&nbsp;</td><?php endif; ?>
                <td><select class="select" name="actions[<?php echo $channel.'|'.$pkgName ?>]">
                    <option selected="selected"></option>
                    <?php if(isset($pkg['actions']) && is_array($pkg['actions'])): ?>
                        <?php foreach ($pkg['actions'] as $k=>$v): ?>
                        <option value="<?php echo $k ?>"><?php echo $v ?></option>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </select>
                </td>
                <td class="last"><?php echo $pkg['summary']?></td>
            </tr>
        <?php endforeach; /*channel*/ ?>
        </tbody>
    </table>
    <div class="clear"></div>

    <div class="form-btn-set">
        <button type="button" onclick="formSubmit('connect_packages_<?php echo $i ?>')" class="f-right">&Auml;nderungen &uuml;bernehmen</button>
        <?php if (!empty($_GET['updates'])): ?>
        <p class="f-left a-left">
            <span style="background:#f6f6f6;padding:0 5px;">&nbsp;</span> &nbsp;Installiert<br/>
            <span style="background:#fcfbbb;padding:0 5px;">&nbsp;</span> &nbsp;Upgrade verf&uuml;gbar<br/>
        </p>
        <?php endif; ?>
    </div>
</form>
<script type="text/javascript">
$$('#connect_packages_'+<?php echo $i?>+' select').each(function(el){el.value=''});
</script>
<?php if (++$i != $cnt): ?><div class="divider"></div><?php endif ?>
<br/>
<?php endforeach; /*all packages*/ ?>


<?php echo $this->template('connect/iframe.phtml') ?>

<a name="connect_iframe_result"></a>
<div id="connect_iframe_success" style="display:none">
    <?php $this->set('messages', array('success'=>array('Vorgang abgeschlossen. Achten Sie auf die Ausgabe im schwarzen Fenster um wichtige Informationen zum Vorgang zu erhalten.'))) ?>
    <?php echo $this->template('messages.phtml') ?>
    <button onclick="location.reload()">Aktualisieren</button>
</div>
<div id="connect_iframe_failure" style="display:none">
    <?php $this->set('messages', array('error'=>array('Achten Sie auf Fehlermeldungen im schwarzen Fenster und aktualisieren Sie die Seite um Ver&auml;nderungen zu sehen / anzuwenden.'))) ?>
    <?php echo $this->template('messages.phtml') ?>
    <button onclick="location.reload()">Aktualisieren</button>
</div>

<?php echo $this->template('footer.phtml') ?>
